var flag = true;
var pageNum = 1;
$(function(){
    ajaxOrderList(pageNum);

    whileToEnd(function(){
        if(flag){
            ajaxOrderList(pageNum);
        }
   }); 
    

    $(document).on("click",".getGoods",function(){
        var _this = $(this);
        var getGoodsUrl = $(this).attr("data-id");
        $.confirm(["提示","是否确认收货","确认","取消"],function(){
            $.doAjax({
                url:getGoodsUrl,
                type:"post",
                success:function(data){
                    if(data.flag){
                        var addUrl = addCommentURl+"&order_info_id="+data.data.order_info_id;
                        _this.removeClass("getGoods").html("评论晒单").addClass("shaidan");
                        _this.parents("li").find(".order-num span").html("待评论");
                    }else{
                        $.alert(data.msg);
                    }
                }
            }) 
        },""); 
    });
    $(document).on("click",".shaidan",function(){
        $.alert("微信端暂不支持评论，前去PC端评论可获100试豆奖励");
    });

 
})

function ajaxOrderList(num){
    $.doAjax({
        url:listUrl,
        type:"get",
        data:{'page':num},
        success:function(data){
            if(data != ""){
                $('.order-list').append(data);

                //支付倒计时
                $(".countdown_"+num).each(function(){
                    dateCountDown(this,parseInt($(this).attr("data")));
                });
                pageNum++;
                flag = true;
            }else{
                flag = false;
                if(num==1){
                    $('.order-list').append("<li class='nolist'>订单列表为空</li>");
                }else{
                    if($('.order-list li').hasClass('end')){
                        $('.order-list li.end').html('没有更多订单了');
                    }else{
                        $('.order-list').append("<li class='end'>没有更多订单了</li>");
                    }
                    
                }
            }
        }
    }) 
}

